/*global $, jQuery*/
/*
 *{titles}  : Tab切换插件
 *{author}  : daFei
 *{version} : v.0.1
**/

(function($) {
  'use strict';
  $.fn.tab = function(options) {
    var
      defaults = {
        event: 'click'
      },
      settings = $.extend(defaults, options),
      self = this,
      menuItem = self.find('.tab-menu').children('li'),
      wrapItem = self.find('.tab-wrap').children('div'),
      private_handle;

    private_handle = function(elem){
      elem.siblings('li')
          .removeClass('active')
          .end()
          .addClass('active');

      wrapItem.siblings('div')
              .addClass('hide')
              .end()
              .eq(elem.index())
              .removeClass('hide');
    };

    menuItem.on(settings.event, function() {
      private_handle($(this));
    });
  };
}(jQuery));